package com.ppblock.shirox.thymeleaf.dialect;

import com.ppblock.shirox.thymeleaf.processor.HasAllPermissionsElementProcessor;
import com.ppblock.shirox.thymeleaf.processor.HasAnyPermissionsElementProcessor;
import com.ppblock.shirox.thymeleaf.processor.HasPermissionElementProcessor;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author yangjian
 * @since 2017/12/12
 */
public class ShiroxDialect extends AbstractProcessorDialect {

    private static final String NAME = "Shirox";
    private static final String PREFIX = "shirox";

    public ShiroxDialect() {
        super(NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
    }

    @Override
    public Set<IProcessor> getProcessors(String dialectPrefix) {
        return createStandardProcessorsSet(dialectPrefix);
    }

    private static Set<IProcessor> createStandardProcessorsSet(String dialectPrefix) {
        LinkedHashSet processors = new LinkedHashSet();
        processors.add(new HasAnyPermissionsElementProcessor(dialectPrefix));
        processors.add(new HasAllPermissionsElementProcessor(dialectPrefix));
        processors.add(new HasPermissionElementProcessor(dialectPrefix));
        return processors;
    }
}
